<?php

namespace App\Admin\Controllers;

use App\Models\RecordStaffPractice;
use App\Models\Store;
use App\Models\StoreDetail;
use Carbon\Carbon;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Illuminate\Support\Arr;

class RecordStaffPracticeController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '员工培训';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new RecordStaffPractice());
        $grid->column('store', '所属门店')->display(function ($value) {
        	return Arr::get($value, 'detail.name', '本部');
        });
        $grid->column('staff_practice_time', '费用支出时间');
        $grid->column('price', '金额');
        //$grid->column('picture', __('Picture'));
        $grid->column('remark', __('Remark'));
        //$grid->column('created_at', __('Created at'));
        
        $grid->filter(function ($filter) {
            $filter->disableIdFilter();
            $filter->date('staff_practice_time', '费用支出时间');
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(RecordStaffPractice::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('store_id', __('Store id'));
        $show->field('staff_practice_time', __('Staff practice time'));
        $show->field('price', __('Price'));
        $show->field('picture', __('Picture'));
        $show->field('remark', __('Remark'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('deleted_at', __('Deleted at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new RecordStaffPractice());
        
        
        $store =  Store::all()->pluck('detail.name', 'id')->toArray();
		$store[0] = '本部';
		ksort($store);
        $form->select('store_id', __('Store id'))
	        ->options($store);
        $form->datetime('staff_practice_time', '费用支出时间')->required();
        $form->currency('price', '金额')->symbol('￥')->required();
        $form->multipleImage('picture', '合同发票')->removable();
        $form->textarea('remark', __('Remark'));
        
        return $form;
    }
}
